﻿using NewsMine.Storage.SQLite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data.SQLite;
using NewsMine.DomainObjects;
using System.Collections.Generic;

namespace NewsMine.Storage.Tests
{
    
    
    /// <summary>
    ///This is a test class for SQLiteKeyValueHelperTest and is intended
    ///to contain all SQLiteKeyValueHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SQLiteKeyValueHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SQLiteKeyValueHelper Constructor
        ///</summary>
        [TestMethod()]
        public void SQLiteKeyValueHelperConstructorTest()
        {
            string sqliteFilePath = @"C:\keyvaluestore.db";
            SQLiteKeyValueHelper target = new SQLiteKeyValueHelper(sqliteFilePath);

        }

        /// <summary>
        ///A test for AreExists
        ///</summary>
        [TestMethod()]
        public void AreExistsTest()
        {
            string sqliteFilePath = string.Empty; // TODO: Initialize to an appropriate value
            SQLiteKeyValueHelper target = new SQLiteKeyValueHelper(sqliteFilePath); // TODO: Initialize to an appropriate value
            string[] keys = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.AreExists(keys);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Get
        ///</summary>
        [TestMethod()]
        public void GetTest()
        {
            string sqliteFilePath = @"C:\temp\DataStore\KeyValueStores\WebSiteInfoMasterStore\sqliteKVItems.db";
            SQLiteKeyValueHelper target = new SQLiteKeyValueHelper(sqliteFilePath); 
            var Items  = target.GetAll();

            List<KeyValueItem> result = new List<KeyValueItem>();

            foreach (var item in Items)
            {
                result.Add((KeyValueItem)NewsMine.Utilities.ObjectByteArrayConverter.ByteArrayToObject(item));
            }

            int count = result.Count;
        }

        /// <summary>
        ///A test for GetBytes
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NewsMine.Storage.dll")]
        public void GetBytesTest()
        {
            SQLiteDataReader reader = null; // TODO: Initialize to an appropriate value
            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = SQLiteKeyValueHelper_Accessor.GetBytes(reader);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for IsExists
        ///</summary>
        [TestMethod()]
        public void IsExistsTest()
        {
            string sqliteFilePath = string.Empty; // TODO: Initialize to an appropriate value
            SQLiteKeyValueHelper target = new SQLiteKeyValueHelper(sqliteFilePath); // TODO: Initialize to an appropriate value
            string key = string.Empty; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.IsExists(key);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for MainMethod
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NewsMine.Storage.dll")]
        public void MainMethodTest()
        {
           
        }

        /// <summary>
        ///A test for Set
        ///</summary>
        [TestMethod()]
        public void SetTest()
        {
            string sqliteFilePath = @"C:\keyvaluestore.db";
            SQLiteKeyValueHelper target = new SQLiteKeyValueHelper(sqliteFilePath);
            string key = "Surendra reddy'adlkfuarlksdlkfas";
            byte[] data = new byte[] { 2,3,34,12};

            data = null;

            target.Set(key , data);

            //DateTime startTime = DateTime.Now;

            //for (int i = 0; i < 2; i++)
            //{
            //    target.Set(key + i.ToString(), data);
            //}

            //DateTime endTime = DateTime.Now;

            //var diff = endTime - startTime;

            byte[] result = target.Get(key);
        }
    }
}
